<template>
  <div>
    <div class="topInfo">
      <div class="img">
        <img
          src="https://akk.028wkf.cn/kdb-weapp-img/new-kdb-xcx/icon/grsj.png"
          mode="scaleToFill"
        />
      </div>
      <p class="identity">
        当前身份：
        <span>{{newIdentityShow[showIdentity]}}</span>
      </p>
      <!-- <p class="hint">
        立即申请成为
        <span>【实业宝】</span>，开通线上商城，获得更多权限！
      </p>-->
    </div>
    <div class="stateLink">
      <i-cell-group>
        <!-- <i-cell @click="entityClick" is-link>
          <p slot="icon" class="left">
            <span>实</span>成为实体店
          </p>
          <p slot="footer" :style="{color:color}">{{entity}}</p>
        </i-cell>
        <i-cell @click="entity1Click" is-link>
          <p slot="icon" class="left">
            <span>实</span>成为网红店
          </p>
          <p slot="footer" :style="{color:color1}">{{entity1}}</p>
        </i-cell>-->
        <i-cell @click="entity2Click" is-link>
          <p slot="icon" class="left">
            <span>兜</span>成为兜货商
          </p>
          <span slot="footer" :style="{color:color2}">{{entity2}}</span>
        </i-cell>
        <i-cell @click="entity3Click" is-link>
          <p slot="icon" class="left">
            <span>供</span>成为供应商
          </p>
          <span slot="footer" :style="{color:color3}">{{entity3}}</span>
        </i-cell>
      </i-cell-group>
    </div>
  </div>
</template>

<script>
import {} from '@/utils'
import {
  FIND_SHOP_CHANGE_APPLY_PAGE_API,
  FIND_SHOP_KIND_APPLY_PAGE_API,
  FIND_SHOP_BASE_INFO
} from '@/api'

export default {
  components: {},
  props: {},
  data () {
    return {
      entity: '',
      color: '',
      state: '',
      entity1: '',
      color1: '',
      state1: '',
      entity2: '',
      color2: '',
      state2: '',
      entity3: '',
      color3: '',
      state3: '',
      getShopIdentity: '',
      shopIdentityObj: {
        ENTITY: '实业宝',
        VIRTUAL: '网商宝',
        PERSONAL: '创业宝'
      },
      newIdentityShow: {
        DEALER: '兜货商',
        SUPPLIER: '供应商'
      },
      showIdentity: ''
    }
  },
  computed: {
    account () {
      return this.$store.state.account
    }
    // shopIdentity () {
    //   let shopIdentity = this.$cookie.get('account').shopIdentity
    //   if (shopIdentity === 'ENTITY') {
    //     return '实业宝'
    //   } else if (shopIdentity === 'VIRTUAL') {
    //     return '网商宝'
    //   } else {
    //     return '创业宝'
    //   }
    // }
  },
  watch: {},
  created () {},
  mounted () {},
  onShow () {
    this.init()
    this._findShopChangeApplyPageApi()
    this._findShopKindApplyPageApi()
    this._findShopKindApplyPageApi2()
    // this.getShopIdentityParams() // 21200116 更换了
  },
  methods: {
    entityClick () {
      const vm = this
      if (vm.showIdentity === 'ENTITY') {
        vm.$toast('你已成为实体店，请勿重新申请')
        return false
      }
      /* 成为网红店后能够成为实体店 */
      // else if (vm.showIdentity === 'VIRTUAL') {
      //   vm.$toast('你已是网红店，不能申请实体店')
      //   return false
      // }
      if (vm.getShopIdentity === 'ENTITY' && vm.state === '0') {
        vm.$toast('实体店审核中，请勿重新申请')
      } else if (vm.getShopIdentity === 'ENTITY' && vm.state === '1') {
        vm.$toast('你已成为实体店，请勿重新申请')
      } else {
        vm.$router.push('/pages/mine/shop-info/merchant/entity/main')
      }
    },
    entity1Click () {
      const vm = this
      if (vm.showIdentity === 'ENTITY') {
        vm.$toast('你已成为实体店，无需申请网红店')
        return false
      } else if (vm.showIdentity === 'VIRTUAL') {
        vm.$toast('你已是网红店，请勿重新申请')
        return false
      }
      if (vm.getShopIdentity === 'ENTITY' && vm.state === '0') {
        vm.$toast('你已是实体店，无需申请网红店')
      } else if (vm.getShopIdentity === 'ENTITY' && vm.state === '1') {
        vm.$toast('你正在申请实体店，不能申请网红店')
      } else if (vm.getShopIdentity === 'VIRTUAL' && vm.state === '0') {
        vm.$toast('网红店审核中，请勿重新申请')
      } else if (vm.getShopIdentity === 'VIRTUAL' && vm.state === '1') {
        vm.$toast('你已成为网红店，不能申请网红店')
      } else {
        vm.$router.push('/pages/mine/shop-info/merchant/online/main')
      }
      // if (vm.state1 === '1') {
      //   vm.$toast('你已成为网红店，请勿重新申请')
      // } else if (vm.state1 === '0') {
      //   vm.$toast('网红店审核中，请勿重新申请')
      // } else if (vm.state === '1') {
      //   vm.$toast('你已成为实体店，不能申请网红店')
      // } else if (vm.state === '0') {
      //   vm.$toast('你已申请实体店，不能申请网红店')
      // } else {
      //   vm.$router.push('/pages/mine/shop-info/merchant/online/main')
      // }
    },
    entity2Click () {
      const vm = this
      if (vm.showIdentity === 'ENTITY') {
        if (
          (vm.getShopIdentity === 'ENTITY' && vm.state === '1') ||
          vm.state2 === ''
        ) {
          vm.$router.push('/pages/mine/shop-info/merchant/grocers/main')
        } else if (vm.state2 === '1') {
          vm.$toast('你已成为兜货商，请勿重新申请')
        } else if (vm.state2 === '0') {
          vm.$toast('兜货商审核中，请勿重新申请')
        } else {
          vm.$toast('请先成为实体店')
        }
        return false
      } else {
        vm.$toast('请先成为实体店')
      }
      // else if (vm.showIdentity === 'VIRTUAL') {
      //   vm.$toast('你已是网红店，不能成为兜货商')
      //   return false
      // }

      // if (vm.state === '1') {
      //   vm.$router.push('/pages/mine/shop-info/merchant/grocers/main')
      // } else if (vm.state2 === '1') {
      //   vm.$toast('你已成为兜货商，请勿重新申请')
      // } else if (vm.state2 === '0') {
      //   vm.$toast('兜货商审核中，请勿重新申请')
      // } else {
      //   vm.$toast('请先成为实体店')
      // }
    },

    entity3Click () {
      const vm = this
      if (vm.showIdentity === 'ENTITY') {
        if (
          (vm.getShopIdentity === 'ENTITY' && vm.state === '1') ||
          vm.state3 === ''
        ) {
          vm.$router.push('/pages/shop-management/dis/turn-into-supplier/main')
        } else if (vm.state3 === '1') {
          vm.$toast('你已成为兜货商，请勿重新申请')
        } else if (vm.state3 === '0') {
          vm.$toast('兜货商审核中，请勿重新申请')
        } else {
          vm.$toast('请先成为实体店')
        }
        return false
      } else {
        vm.$toast('请先成为实体店')
      }
    },
    _findShopChangeApplyPageApi () {
      const vm = this
      let params = {
        cellphone: vm.$cookie.get('account').cellphone,
        shopId: vm.$cookie.get('account').shopId
      }
      FIND_SHOP_CHANGE_APPLY_PAGE_API(params, 1, 1)
        .then(r => {
          if (r.data.code === '0') {
            if (r.data.data.list.length) {
              let state = r.data.data.list[0].state
              let shopIdentity = r.data.data.list[0].shopIdentity
              vm.state = state
              vm.getShopIdentity = shopIdentity
              if (shopIdentity === 'ENTITY') {
                if (state === '0') {
                  vm.entity = '申请中'
                  vm.color = '#FD3838'
                } else if (state === '1') {
                  vm.entity = '已通过'
                  vm.color = '#009944'
                } else if (state === '2') {
                  vm.entity = '未通过'
                  vm.color = 'FD3838'
                } else {
                  vm.entity = ''
                }
              } else if (shopIdentity === 'VIRTUAL') {
                if (state === '0') {
                  vm.entity1 = '申请中'
                  vm.color1 = '#FD3838'
                } else if (state === '1') {
                  vm.entity1 = '已通过'
                  vm.color1 = '#009944'
                } else if (state === '2') {
                  vm.entity1 = '未通过'
                  vm.color1 = 'FD3838'
                } else {
                  vm.entity1 = ''
                }
              }
            } else {
              vm.entity = ''
              vm.entity1 = ''
            }
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    },
    _findShopKindApplyPageApi () {
      const vm = this
      let params = {
        phone: vm.$cookie.get('account').cellphone,
        shopId: vm.$cookie.get('account').shopId,
        shopKind: 'DEALER'
      }
      FIND_SHOP_KIND_APPLY_PAGE_API(params, 1, 1)
        .then(r => {
          if (r.data.code === '0') {
            if (r.data.data.list.length) {
              let state = r.data.data.list[0].state
              vm.state2 = state
              if (state === '0') {
                vm.entity2 = '申请中'
                vm.color2 = '#FD3838'
              } else if (state === '1') {
                vm.entity2 = '已通过'
                vm.color2 = '#009944'
              } else if (state === '2') {
                vm.entity2 = '未通过'
                vm.color2 = 'FD3838'
              } else {
                vm.entity2 = ''
              }
            } else {
              vm.entity2 = ''
            }
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    },
    _findShopKindApplyPageApi2 () {
      const vm = this
      let params = {
        phone: vm.$cookie.get('account').cellphone,
        shopId: vm.$cookie.get('account').shopId,
        shopKind: 'SUPPLIER'
      }
      FIND_SHOP_KIND_APPLY_PAGE_API(params, 1, 1)
        .then(r => {
          if (r.data.code === '0') {
            if (r.data.data.list.length) {
              let state = r.data.data.list[0].state
              vm.state3 = state
              if (state === '0') {
                vm.entity3 = '申请中'
                vm.color3 = '#FD3838'
              } else if (state === '1') {
                vm.entity3 = '已通过'
                vm.color3 = '#009944'
              } else if (state === '2') {
                vm.entity3 = '未通过'
                vm.color3 = 'FD3838'
              } else {
                vm.entity3 = ''
              }
            } else {
              vm.entity3 = ''
            }
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    }, // to do 暂时将就这个用到，没得时间优化
    getShopIdentityParams () {
      const vm = this
      FIND_SHOP_BASE_INFO(vm.account.shopId).then(r => {
        if (r.data.code === '0') {
          vm.showIdentity = r.data.data.shopIdentity
        } else {
          vm.$toast(r.data.message)
        }
      })
    },
    init () {
      this.entity = ''
      this.color = ''
      this.state = ''
      this.entity1 = ''
      this.color1 = ''
      this.state1 = ''
      this.entity2 = ''
      this.color2 = ''
      this.state2 = ''
      this.getShopIdentity = ''
      this.showIdentity = this.$cookie.get('account').shopKind
    }
  }
}
</script>

<style lang="scss" scoped>
@import 'static/styles/color.scss';
.topInfo {
  width: 90%;
  margin: 50px auto 20px;
  .img {
    width: 60px;
    height: 60px;
    border: 1px dashed #666;
    margin: auto;
    img {
      width: 58px;
      height: 58px;
    }
  }
  .identity {
    font-size: 16px;
    color: #000;
    font-weight: 600;
    text-align: center;
    margin: 20px 0;
    span {
      color: #fd3838;
    }
  }
  .hint {
    color: #222;
    font-size: 14px;
    line-height: 20px;
    span {
      color: #5d93fd;
    }
  }
}
.stateLink {
  .left {
    display: flex;
    align-items: center;
    span {
      width: 18px;
      height: 18px;
      background: #fd3838;
      border-radius: 5px;
      color: #fff;
      font-size: 12px;
      display: block;
      text-align: center;
      line-height: 18px;
      margin-right: 5px;
    }
  }
}
</style>
